<?php
// Copyright 2022 Hackware SpA <human@hackware.cl>
// This file is part of "Hackware Web Services Payment" and licensed under
// the terms of the GNU Affero General Public License version 3, or (at your
// option) a later version. You should have received a copy of this license
// along with the software. If not, see <https://www.gnu.org/licenses/>.

$countries = explode(' ', env('DLOCALGO_COUNTRIES'));
$country_props = [
    [
        'const' => 'AR',
        'title' => 'Argentina',
        'description' =>
            'Efectivo, transferencia bancaria y tarjetas' .
            ' en Argentina',
        'image' => env('APP_URL') . '/img/flags/ar.svg',
    ],
    [
        'const' => 'BO',
        'title' => 'Bolivia',
        'description' => 'Transferencia bancaria en' .
            ' Bolivia',
        'image' => env('APP_URL') . '/img/flags/bo.svg',
    ],
    [
        'const' => 'BR',
        'title' => 'Brasil',
        'description' =>
            'Efectivo, transferencia bancaria y tarjetas' .
            ' en Brasil',
        'image' => env('APP_URL') . '/img/flags/br.svg',
    ],
    [
        'const' => 'CL',
        'title' => 'Chile',
        'description' =>
            'Efectivo, transferencia bancaria y tarjetas' .
            ' en Chile',
        'image' => env('APP_URL') . '/img/flags/cl.svg',
    ],
    [
        'const' => 'CO',
        'title' => 'Colombia',
        'description' =>
            'Efectivo, transferencia bancaria y tarjetas' .
            ' en Colombia',
        'image' => env('APP_URL') . '/img/flags/co.svg',
    ],
    [
        'const' => 'EC',
        'title' => 'Ecuador',
        'description' => 'Efectivo y tarjetas en Ecuador',
        'image' => env('APP_URL') . '/img/flags/ec.svg',
    ],
    [
        'const' => 'MX',
        'title' => 'México',
        'description' =>
            'Efectivo, transferencia bancaria y tarjetas' .
            ' en México',
        'image' => env('APP_URL') . '/img/flags/mx.svg',
    ],
    [
        'const' => 'PA',
        'title' => 'Panamá',
        'description' => 'Tarjetas en Panamá',
        'image' => env('APP_URL') . '/img/flags/pa.svg',
    ],
    [
        'const' => 'PE',
        'title' => 'Perú',
        'description' =>
            'Efectivo, transferencia bancaria y tarjetas' .
            ' en Perú',
        'image' => env('APP_URL') . '/img/flags/pe.svg',
    ],
    [
        'const' => 'PY',
        'title' => 'Paraguay',
        'description' => 'Efectivo y tarjetas en Paraguay',
        'image' => env('APP_URL') . '/img/flags/py.svg',
    ],
    [
        'const' => 'UY',
        'title' => 'Uruguay',
        'description' => 'Efectivo y tarjetas en Uruguay',
        'image' => env('APP_URL') . '/img/flags/uy.svg',
    ]
];

return [
    'class' => '\Hawese\Payment\Gateways\DLocalGoGateway',
    'countries' => $countries,
    'test_mode' => env('DLOCALGO_TEST_MODE', false),
    'credentials' => [
        'apiKey' => env('DLOCALGO_API_KEY'),
        'secretKey' => env('DLOCALGO_SECRET_KEY'),
    ],
    'payment_methods' => [
        'purchase' => 'country',
    ],
    'schemas' => [
        'purchase' => [
            'required' => [
                'currency',
                'amount',
            ],
            'standard_map' => [
                'subject' => 'description',
                'email' => ['payer' => 'email'],
                'due_amount' => 'amount',
                'payment_method' => 'country',
                'currency' => 'currency'
            ],
            'properties' => [
                'description' => [
                    'title' => 'Descripción',
                    'type' => 'string',
                ],
                'currency' => [
                    'title' => 'Moneda',
                    'type' => 'string',
                    'enum' => ['USD'],
                    'default' => 'USD',
                    'readOnly' => true,
                ],
                'amount' => [
                    'title' => 'Monto',
                    'type' => 'number',
                    'multipleOf' => 0.01,
                ],
                'payer' => [
                    'title' => 'Pagador',
                    'type' => 'object',
                    'properties' => [
                        /*
                        'id' => [
                            'title' => 'id',
                            'type' => 'string',
                        ],
                        'name' => [
                            'title' => 'Nombre',
                            'type' => 'string',
                        ],
                        */
                        'email' => [
                            'title' => 'Email',
                            'type' => 'string',
                            'format' => 'idn-email',
                        ],
                        /*
                        'phone' => [
                            'title' => 'Teléfono',
                            'type' => 'string',
                        ],
                        'document_type' => [
                            'title' => 'Tipo de documento',
                            'type' => 'string',
                        ],
                        'document' => [
                            'title' => 'Documento',
                            'type' => 'string',
                        ],
                        'user_reference' => [
                            'title' => 'Referencia de usuario',
                            'type' => 'string',
                        ],
                        */
                    ],
                ],
                'country' => [
                    'title' => 'País',
                    'type' => 'string',
                    'oneOf' => array_filter(
                        $country_props,
                        function($prop) use ($countries) {
                            return in_array($prop['const'], $countries);
                        }
                    ),
                ],
            ],
        ],
    ],
];
